<template>
  <div class="content-Modal">
    <cus-modal ref="modal" width="540" title="审核意见" closable>
      <div :style="{height: data.length>0?'190px' : ''}" style="overflow-y:auto;overflow-x: hidden;">
        <div class="mb_10" v-for="(item,index) in data" :key="index">
        <div class="fl mb_10">
          <div>{{ `${index+1}、${item.gmtCreate}` }}</div>
          <div class="text ml_24">{{ item.auditStatusName }}</div>
        </div>
        <div>
          <p class="ml_10" style="padding: 0 10px 0 0;">{{ item.auditComment ? item.auditComment : '暂无!' }}</p>
        </div>
      </div>
      </div>
        <Input
          class="inputStyle"
          v-model="auditComment"
          type="textarea"
          maxlength="100"
          show-word-limit
          :autosize="{ minRows: 7, maxRows: 7 }"
          placeholder="请输入审核意见..."
        />
      <div slot="footer">
        <slot name="footer">
          <div class="modal-footer">
            <cus-button
              size="small"
              type="error"
              class="mr_2"
              v-if="form.organAuditState != 2"
              @onClick="onReject()"
              >驳回</cus-button
            >
            <cus-button type="success" size="small" v-if="form.organAuditState != 2" @onClick="onOk()"
              >通过</cus-button
            >
            <cus-button type="primary" size="small" v-if="form.organAuditState == 2" @onClick="onCancel()"
              >撤销审核</cus-button
            >
          </div>
        </slot>
      </div>
      <Spin size="large" fix v-if="loading"></Spin>
    </cus-modal>
  </div>
</template>

<script>
import { postPurchasingPlansAudit, postPurchasingPlansAuditLog, postPurchasingPlansCancel } from "@/api/organ/manager";

export default {
  name: "",
  computed: {},
  data() {
    return {
      loading: false,
      form: {},
      data: [],         // 提交Excel效验接口返回提示err
      auditComment: "", // 审核意见
    };
  },
  mounted() {},
  methods: {
    show(nVew) {
      this.$refs["modal"].show = true;
      this.auditComment='';
      this.form = nVew;
      this.postPurchasingPlansAuditLogApi();
    },
    onOk() {
      this.postPurchasingPlansAuditApi(2)
    },
    onReject() {
      if(this.auditComment!=''){
        this.postPurchasingPlansAuditApi(3)
      } else {
        this.$Message.info('请输入审核意见!')
      }
    },
    onCancel() {
      this.postPurchasingPlansCancelApi();
    },
    // 审核日志-----------------------接口
    postPurchasingPlansAuditLogApi() {
      this.loading = true;
      return new Promise((resolve) => {
        postPurchasingPlansAuditLog({ periodId: this.form.id }).then((res) => {
          this.loading = false;
          if (res.code === 1) {
            this.data = res.data;
            resolve();
          }
        });
      });
    },
    // 审核---------------------------接口
    postPurchasingPlansAuditApi(number) {
      this.loading = true;
      return new Promise((resolve) => {
        postPurchasingPlansAudit({
          auditComment: this.auditComment,
          periodId: this.form.id,
          auditStatus: number
        }).then((res) => {
          this.loading = false;
          if (res.code === 1) {
            let content = number == 3 ? '驳回成功' : '审核通过'
            this.$Message.success(content)
            this.$refs["modal"].show = false;
            this.$parent.onInit();
            resolve();
          }
        });
      });
    },
    // 取消审核-----------------------接口
    postPurchasingPlansCancelApi() {
      this.loading = true;
      return new Promise((resolve) => {
        postPurchasingPlansCancel({
          periodId: this.form.id,
          auditComment: this.auditComment,
        }).then((res) => {
          this.loading = false;
          if (res.code === 1) {
            this.$Message.success('成功取消审核')
            this.$refs["modal"].show = false;
            this.$parent.onInit();
            resolve();
          }
        });
      });
    }
  },
  computed: {},
  watch: {},
};
</script>

<style lang="less" scoped>
// .content-Modal {
/deep/.modal-header {
  display: flex;
  justify-content: center;
  font-size: 20px;
  font-family: PingFang SC-Regular, PingFang SC;
  font-weight: 400;
  color: #333333;
  line-height: 23px;
}
/deep/.ivu-modal-header {
  border-bottom: none;
}
/deep/.ivu-modal-footer {
  border-top: none;
}
.mt_10 {
  margin-top: 10px;
}
.fl {
  display: flex;
}
.text {
  font-size: 14px;
  font-family: PingFang SC-Regular, PingFang SC;
  font-weight: 400;
  color: #1e6fff;
}
.inputStyle {
  background: #f3f5f9;
  border-radius: 6px 6px 6px 6px;
  opacity: 1;
  margin-top: 10px;
  margin-bottom: -20px;
}
/*
*滚动条样式
*/
::-webkit-scrollbar{

width:10px;

height:16px;

background-color:#F5F5F5;

}

/*定义滚动条轨道

内阴影+圆角*/

::-webkit-scrollbar-track{

-webkit-box-shadow:inset 0 0 6px rgba(0,0,0,0.3);

border-radius:10px;

background-color:#F5F5F5;

}

/*定义滑块

内阴影+圆角*/

::-webkit-scrollbar-thumb{

border-radius:10px;

-webkit-box-shadow:inset 0 0 6px rgba(0,0,0,.3);

background-color:#2D8CF0;

}
// }
</style>
